import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_shop/model/cartInfo.dart';
import 'package:flutter_shop/provide/cart.dart';
import 'package:provide/provide.dart';

class CartCount extends StatelessWidget {
  CartInfoMode cartInfoMode;

  CartCount({Key key, this.cartInfoMode}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      width: ScreenUtil().setWidth(165),
      margin: EdgeInsets.only(top: 5.0),
      decoration:
          BoxDecoration(border: Border.all(color: Colors.black12, width: 0.5)),
      child: Row(
        children: <Widget>[
          _addBtn(context),
          _count(),
          _reduceBtn(context),
        ],
      ),
    );
  }

  Widget _reduceBtn(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      height: ScreenUtil().setHeight(45),
      width: ScreenUtil().setWidth(45),
      decoration: BoxDecoration(
          color: Colors.white,
          border: Border(left: BorderSide(color: Colors.black12, width: 0.5))),
      child: InkWell(
        onTap: () {
          Provide.value<CartProvide>(context)
              .addOrReduceAction(cartInfoMode, 'add');
        },
        child: Text('+'),
      ),
    );
  }

  Widget _addBtn(BuildContext context) {
    return InkWell(
      onTap: () {
        Provide.value<CartProvide>(context).addOrReduceAction(cartInfoMode, 'reduce');
      },
      child: Container(
        alignment: Alignment.center,
        height: ScreenUtil().setHeight(45),
        width: ScreenUtil().setWidth(45),
        decoration: BoxDecoration(
            color: Colors.white,
            border:
                Border(right: BorderSide(color: Colors.black12, width: 0.5))),
        child: Text('-'),
      ),
    );
  }

  Widget _count() {
    return Container(
      alignment: Alignment.center,
      height: ScreenUtil().setHeight(45),
      width: ScreenUtil().setWidth(70),
      decoration: BoxDecoration(
        color: Colors.white,
      ),
      child: Text('${cartInfoMode.count}'),
    );
//    return Provide<CartProvide>(
//      builder: (context,child,carInfo){
//        return Container(
//          alignment: Alignment.center,
//          height: ScreenUtil().setHeight(45),
//          width: ScreenUtil().setWidth(70),
//          decoration: BoxDecoration(
//            color: Colors.white,
//          ),
//          child: Text('1'),
//        );
//      },
//    );
  }
}
